layui.define(['jquery','form'], function (exports) {
	"use strict";
	var $ = layui.jquery,form=layui.form,object = {
		c: {data:[]}, // 配置项
		f: function (c) { // 数据初始化
			var s=new Date().getTime(),t = this;
			t.c.id = c.id?c.id:'simple_table_TP_ProductBasis';
			t.c.tableId = c.tableelem?c.tableelem:'table-'+s;
			t.c.data = c.data; // 数据
			//将表单数据带入js
			t.c.formObj = c.formObj;
			/**自定义的字段，是否流转中**/
			t.c.onProcess = c.onProcess;


		},
		load:function () { // 加载控件
			var h = ``
				+ `<div class="layui-form layui-form-item" lay-filter="` + this.id + `" style="background-color: #ffffff;">`
				+ `<label style="font-weight: 700;font-size: 18px; padding: 5px;">子件信息</label>`
				+ `</div>`;

			if($('#onProcessBySon').val() == 0) {
				h += `<div class="layui-table-tool" style="padding: 0; min-height: 0; background-color: #ffffff;">`
					+ `<div class="layui-table-tool-temp">`
					+ `<div class="layui-btn-container">`
					+ `<a class="layui-btn layui-btn-normal layui-btn-sm " lay-event="event-to-select"><i class="iconfont icon-add-btn"></i>新增</a>`
					+ `</div>`
					+ `</div>`
					+ `</div>`
			}
			h+= `<div class="layui-form layui-form-item" pane>`
				+ `<div id="`+this.c.tableId+`">`
				+ this.loadTable()
				+ `</div>`
				+ `</div>`
				+ `</div>`;
			$('#'+this.c.id).html(h);
			this.listenBtn();
		},
		loadTable:function () { // 加载表格
			return ``
				+ `<div class="layui-table-box">`
				+ `<div class="layui-table-header" style="height: 300px; max-height: 300px; overflow: auto; background-color: #ffffff;">`
				+ `<table cellspacing="0" cellpadding="0" border="0" class="layui-table" lay-skin="grid" lay-even="" style="margin: 0;">`
				+ `<thead>`
				+ this.loadTableOfThead()
				+ `</thead>`
				+ `<tbody>` + this.loadTableOfTbody()+`</tbody>`
				+ `</table>`
				+ `</div>`
				+ `</div>`;
		},
		loadTableOfThead:function () { // 加载表头
			var h = `<thead>`;
			h +=`<tr>`;
			h += `<th style="display: none;">id</th>`;
			h += `<th style="width:5%; text-align: center; color: #000000;">母件编码</th>`;
			h += `<th style="width:5%; text-align: center; color: #000000;">子件编码</th>`;
			h += `<th style="width:5%; text-align: center; color: #000000;">子件名称</th>`;
			h += `<th style="width:5%; text-align: center; color: #000000;">子件数量</th>`;
			h += `<th style="width:5%; text-align: center; color: #000000;">子件单价</th>`;
			h += `<th style="width:5%; text-align: center; color: #000000;">采购链接</th>`;
			h += `<th style="width:5%; text-align: center; color: #000000;">铺货标识</th>`;
			h += `<th style="width:5%; text-align: center; color: #000000;">子件备注</th>`;

			if($('#onProcessBySon').val() == 0) {
				h += `<th style="width:4%; text-align: center; color: #000000;">操作</th>`;
			}
			h += `</tr>`;
			h + `</thead>`;
			return h;
		},
		loadTableOfTbody:function () { // 加载表tbody
			var t = this;
			var h = `<tbody>`;
			for(var i=0;i<t.c.data.length;i++){
				h += `<tr>`;
				h += `<td style="display: none; text-align:center; padding: 0;">` + t.c.data[i].id + `</td>`;
				h += `<td style="text-align:center; padding: 0;">` + t.c.data[i].pcode + `</td>`;
				h += `<td style="text-align:center; padding: 0;">` + t.c.data[i].code + `</td>`;

				if($('#onProcessBySon').val() == 0) {//可编辑
					h += `<td style="text-align:center;padding:0;"><input type="text" maxlength="400"  class="text_align_center layui-input"  lay-filter="_input"  data-type="name" value="` + (t.c.data[i].name!=undefined?t.c.data[i].name:'') + `" data-index="` + i + `"></td>`;
					h += `<td style="text-align:center;padding:0;"><input type="number" maxlength="15"  min="0.01" class="text_align_center layui-input"  lay-filter="_input"  data-type="num" value="` + (t.c.data[i].num!=undefined?t.c.data[i].num:'') + `" data-index="` + i + `"></td>`;
					h += `<td style="text-align:center;padding:0;"><input type="number" maxlength="15"  min="0.01" class="text_align_center layui-input"  lay-filter="_input"  data-type="bprice" value="` + (t.c.data[i].bprice!=undefined?t.c.data[i].bprice:'') + `" data-index="` + i + `"></td>`;
					h += `<td style="text-align:center;padding:0;"><input type="text" maxlength="200"  class="text_align_center layui-input"  lay-filter="_input"  data-type="linkIn" value="` + (t.c.data[i].linkIn!=undefined?t.c.data[i].linkIn:'') + `" data-index="` + i + `"></td>`;
					h += `<td style="text-align:center;padding:0;"><input type="number" maxlength="15"  min="0" class="text_align_center layui-input"  lay-filter="_input"  data-type="linkInMark" value="` + (t.c.data[i].linkInMark!=undefined?t.c.data[i].linkInMark:'') + `" data-index="` + i + `"></td>`;
					h += `<td style="text-align:center;padding:0;"><input type="text" maxlength="200"  class="text_align_center layui-input"  lay-filter="_input"  data-type="remark" value="` + (t.c.data[i].remark!=undefined?t.c.data[i].remark:'') + `" data-index="` + i + `"></td>`;
					h += `<td style="text-align:center; padding: 0;">`;
					h += `<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" data-index="` + i + `" lay-filter="removeSingle"><i class="layui-icon layui-icon-delete"></i>删除</button></td>`;
				}else {
					h += `<td style="text-align:center; padding: 0;">` + (t.c.data[i].name!=undefined?t.c.data[i].name:'') + `</td>`;
					h += `<td style="text-align:center; padding: 0;">` + (t.c.data[i].num!=undefined?t.c.data[i].num:'') + `</td>`;
					h += `<td style="text-align:center; padding: 0;">` + (t.c.data[i].bprice!=undefined?t.c.data[i].bprice:'') + `</td>`;
					h += `<td style="text-align:center; padding: 0;">` + (t.c.data[i].linkIn!=undefined?t.c.data[i].linkIn:'') + `</td>`;
					h += `<td style="text-align:center; padding: 0;">` + (t.c.data[i].linkInMark!=undefined?t.c.data[i].linkInMark:'') + `</td>`;
					h += `<td style="text-align:center; padding: 0;">` + (t.c.data[i].remark!=undefined?t.c.data[i].remark:'') + `</td>`;
				}
				h+= `</tr>`;
			}

			h += `</tbody>`;
			return h;
		},
	};
	exports('simple_table_TP_ProductBasis', object);
});